package cc.miwuya.complain.service.impl;

import cc.miwuya.complain.domain.Complain;
import cc.miwuya.complain.mapper.ComplainMapper;
import cc.miwuya.complain.service.ComplainService;
import cn.hutool.core.date.DateField;
import cn.hutool.core.date.DateUnit;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.HashMap;
import java.util.List;

/**
 * @author 杩烽浘妫灄
 * @description 针对表【complain(投诉表)】的数据库操作Service实现
 * @createDate 2024-02-22 20:10:28
 */
@Service
public class ComplainServiceImpl extends ServiceImpl<ComplainMapper, Complain>
        implements ComplainService {
    @Resource
    ComplainMapper complainMapper;
    @Override
    public Object getPage(Page page, String name, Long residentialId, List<Integer> role) {
        Page<Complain> complainPage = null;
        if (StrUtil.isEmpty(name) || name.equals("null")) {
            complainPage = page(page, new QueryWrapper<Complain>().eq("residential_id", residentialId).in("admin_unit_id", role));
        } else {
            complainPage = page(page, new QueryWrapper<Complain>().eq("residential_id", residentialId).like("content", name).in("admin_unit_id", role));
        }
        return complainPage;
    }

    @Override
    public Object getOwnerComplainList(Page page, Long residentialId, String name, Long userId) {
        Page<Complain> complainPage = null;
        if (StrUtil.isEmpty(name) || name.equals("null")) {
            complainPage = page(page, new QueryWrapper<Complain>().eq("residential_id", residentialId).eq("user_id", userId));
        } else {
            complainPage = page(page, new QueryWrapper<Complain>().eq("residential_id", residentialId).like("content", name).eq("user_id", userId));
        }
        return complainPage;
    }

    /**
     * 获取投诉数据
     */
    @Override
    public Object getComplainTotal() {
        List<Object> complainTotal = complainMapper.getComplainTotal();
        System.out.println(complainTotal);
        return complainTotal;
    }

    @Override
    public Object getWeekComplainTotal() {
        return complainMapper.getWeekComplainTotal();
    }

}




